package com.sumainfor.wx.tenant.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.tenant.feign.MarketFeignClient;
import com.sumainfor.wx.tenant.feign.OperationsFeignClient;
import com.sumainfor.wx.tenant.service.impl.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 功能描述:
 * 业主相关
 * @Auther: zhlu
 * @Date: 2019/3/13 14:04
 * @Description:
 */
@RestController
@RequestMapping("/owner")
public class OwnerController {

    @Autowired
    MarketFeignClient MarketFeignClient;

    @Autowired
    OwnerService OwnerService;

    @Autowired
    OperationsFeignClient OperationsFeignClient;

    /**
     * 功能描述:
     * 根据微信端的用户手机号判断当前租客是否是业主
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/30 18:43
     */
    @GetMapping("getSigningWechatOwner")
    public JsonResult getSigningWechatOwner(@RequestParam Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = MarketFeignClient.getSigningWechatOwner(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述: 
     * 根据openid获取当前业主托管房源总数
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/13 14:06
     */
    @GetMapping("/getWechatOwnerCount")
    public JsonResult getWechatOwnerCount(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        result.put(OwnerService.getWechatOwnerCount(params));
        return result;
    }

    /**
     * 功能描述: 
     * 根据业主openId获取业主房源情况
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/13 19:46
     */
    @GetMapping("/getWechatOwnerHousing")
    public JsonResult getWechatOwnerHousing(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult<Map<String, Object>> jsonResult = MarketFeignClient.getWechatOwnerHousing(params,pager);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述:
     * 根据业主房源主编号获取房源信息
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/14 11:19
     */
    @GetMapping("/getWechatHousingMap")
    public JsonResult getWechatHousingMap(@RequestParam Map<String,Object>params)throws Exception{
        JsonResult result=new JsonResult();
        Map<String,Object>resultMap=(Map<String,Object>)MarketFeignClient.getWechatHousingMap(params);
        if(resultMap.get("errorCode").equals("0")||resultMap.get("errorCode").toString()=="0"){
            result.put(MarketFeignClient.getWechatHousingMap(params).getResult());
        }else{
            result.putFailed(resultMap.get("errorMessage").toString());
        }
        return result;
    }

    /**
     * 功能描述: 
     * 根据业主手机号获取业主合同，然后获取业主账单资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/1 14:28
     */
    @GetMapping("/getOwnerBillList")
    public JsonResult getOwnerBillList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult<Map<String, Object>> jsonResult = OperationsFeignClient.getOwnerBillList(params,pager);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述: 
     * 根据业主账单编号获取业主银行卡资料、业主账单资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/1 20:01
     */
    @GetMapping("/getOwnerDealPayMap")
    public JsonResult getOwnerDealPayMap(@RequestParam Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = MarketFeignClient.getOwnerDealPayMap(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }
}
